<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: view.html.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class JhtraqViewMilestones extends JView {
    function display($tpl = null) {

		$task = JRequest::getCmd('task', 'index');
		$tpl = $this->$task();
		
        parent::display($tpl);
    }
	
	function index()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->milestones =  $model->getMilestones();
		$this->projects = $model->getProjectList();
		$this->search = JRequest::getVar('search');
		$this->project = JRequest::getVar('project');
		$this->pagination = $model->getPagination();
		
	}
	
	function add()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->milestone = $model->getMilestone(0);
		$this->projects = $model->getProjectList();
		return 'form';
	}
	
	function edit()
	{
	    $cid = JRequest::getVar( 'cid', array(), '', 'array' );
		$model =& JhtraqHelper::getModel('jhtraq');
		$this->milestone = $model->getMilestone($cid[0]);
		$this->projects = $model->getProjectList();
		return 'form';
	}
	
	function save()
	{
		$detail = $_POST;
		$model =& JhtraqHelper::getModel('jhtraq');
		$model->saveMilestone($detail);
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=Milestones", "Milestones Updated");
	}
	
	
	function remove()
	{
		$model =& JhtraqHelper::getModel('jhtraq');
		$model->removeMilestone($_POST['cid']);
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=milestones", "Milestones Deleted");
	}
	
	/**
	 * cancel editing a record
	 * @return void
	*/
	function cancel()
	{
		$mainframe = JFactory::getApplication();
		$mainframe->redirect("index.php?option=com_jhtraq&view=milestones", JText::_('COM_JHTRAQ_OPERATION_CANCELLED'));
	}
	
	
}
?>